#include<iostream>
using namespace std;
typedef long long LL;
LL a, k;
int st[10];
int main()
{
	cin >> a >> k;
	for (int i = 0; i < k; i++) {
		int x;
		cin >> x;
		st[x] = 1;
	}
	LL x = 1e18 / a;
	LL ans = 0;
	for (int i = 1; i <= x; i++) {
		LL y = a * i;
		LL z = y;
		bool f = 0;
		while (z) {
			if (st[z % 10]) {
				f = 1;
				break;
			}
			z /= 10;
		}
		if (!f) {
			ans = y;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}